package com.codemes.happylist.views.dialog;

import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.stage.Screen;
import org.springframework.util.StringUtils;

import java.awt.*;

public class MessageDialog {

    private static final double default_width = Screen.getPrimary().getBounds().getWidth() * 0.3;
    private static final double default_height = Screen.getPrimary().getBounds().getWidth() * 0.05;
    private static final ButtonType btn_confirm = new ButtonType("确认", ButtonBar.ButtonData.CANCEL_CLOSE);
    private static final ButtonType btn_cancel = new ButtonType("取消", ButtonBar.ButtonData.CANCEL_CLOSE);

    public static void alert(String msg) {
        Dialog dialog = buildDialog(msg, "", "确认");
        dialog.getDialogPane().getButtonTypes().add(btn_confirm);
    }

    private static Dialog buildDialog(String msg, String headerText, String title) {
        Dialog dialog = new Dialog();
        dialog.setWidth(default_width);
        dialog.setHeight(default_height);
        if (StringUtils.hasLength(title)) {
            dialog.setTitle(title);
        }
        if (StringUtils.hasLength(headerText)) {
            dialog.setHeaderText(headerText);
        }
        dialog.setContentText(msg);
        dialog.show();
        return dialog;
    }
}
